package com.itbaizhan.paymentdemo.config;

import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

@Data
@Configuration
///读取配置文件
@PropertySource("classpath:zfbpay.properties")
//读取alipay节点
@ConfigurationProperties(prefix = "alipay")
public class ZfbPayConfig {

    //应用id
    private String appId;
    //应用私钥
    private String privateKey;
    //支付宝公钥
    private String publicKey;
    //网关
    private String gateway;
    // 接收结果通知地址
    private String notifyUrl;


    /**
     * 支付宝客户端，用来向支付宝发送信息
     * @return
     */
    @Bean
    public AlipayClient setAlipayClient(){
        //网关，appid  应用私钥  格式  编码格式  支付宝公钥   加密算法
        return new DefaultAlipayClient(gateway,appId,privateKey,"json","utf-8",publicKey,"RSA2");
    }
}
